package com.tengju.data.infrastructure.schedule;

import com.tengju.data.domain.model.alert.AlertEvent;
import com.tengju.data.domain.model.alert.AlertService;
import com.tengju.user.application.chief.ChiefGenSecRelationService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author: 大木
 * @date: 2021/12/24 2:52 下午
 */
@Component
@Slf4j
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class UpdateChiefDepartmentRelationJob {

    private final AlertService alertService;
    private final ChiefGenSecRelationService chiefSecRelationService;

    @XxlJob("updateChiefDepartmentRelationJob")
    public ReturnT<String> execute(String params) {
        try {
            chiefSecRelationService.updateDepartmentInfos();
        } catch (Exception e) {
            String jobName = "总监Sec关系表-更新部门信息任务";
            log.error("{}, jobError", jobName, e);
            AlertEvent event = new AlertEvent(jobName + "异常");
            event.addItem("任务参数",params);
            event.addItem("异常信息",e.getMessage());
            alertService.alert(event);
        }
        return ReturnT.SUCCESS;
    }
}
